/**
 * Copyright (c) 2005 - 2007 FeyaSoft Corp. All Rights Reserved.
 */
package com.feyaSoft.plugin.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author Fenqiang Zhuang
 * @Apr 29, 2007
 * 
 * This file is used to .....
 */
public class JsonUtil {
	// log file
	private final static Logger log = Logger.getLogger(JsonUtil.class);

	/**
	 * create json object from string
	 * 
	 * @param jsonString
	 * @return
	 */
	public static JSONObject getJsonObj(String jsonString) {
		JSONObject jsonObject = null;

		try {
			jsonObject = new JSONObject(jsonString);
		} catch (Exception e) {
			log.error("create json object from string failed - " + jsonString);
		}

		return jsonObject;
	}

	/**
	 * create json object from string
	 * 
	 * @param jsonString
	 * @return
	 */
	public static JSONArray getJsonArray(String jsonString) {
		JSONArray jsonArray = null;

		try {
			jsonArray = new JSONArray(jsonString);
		} catch (Exception e) {
			log.error("create json array from string failed - " + jsonString);
		}

		return jsonArray;
	}

	/**
	 * read JSON string from request
	 * 
	 * @param request
	 * @param argO
	 * @return
	 */
	public static String readJSONStringFromRequest(HttpServletRequest request,
			String arg) {
		StringBuffer json = new StringBuffer();
		String line = null;

		try {
			// BufferedReader reader = request.getParameter(arg);

		} catch (Exception e) {
			log.error("Error reading JSON string - " + e.getMessage());
		}

		return json.toString();
	}

}
